package com.edu.csu.smartfarm.controller.system;

import com.edu.csu.smartfarm.common.domain.common.AjaxResult;
import com.edu.csu.smartfarm.common.domain.constant.Constants;
import com.edu.csu.smartfarm.common.domain.model.LoginBody;
import com.edu.csu.smartfarm.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
public class SysLoginController {

    @Autowired
    private SysLoginService sysLoginService;

    @PostMapping("/login")
    public AjaxResult sysLogin(@RequestBody LoginBody loginBody){
        AjaxResult ajaxResult = AjaxResult.success();
        //Generate Token
        String token = sysLoginService.login(loginBody.getUsername(),loginBody.getPassword(),loginBody.getCode(),loginBody.getUuid());
        ajaxResult.put(Constants.TOKEN, token);
        return ajaxResult;
    }
}
